package com.qlk.vorder.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.vorder.domain.ReserveSession;
import com.qlk.vorder.domain.query.ReserveSessionQuery;
import com.qlk.vorder.manager.ReserveSessionManager;
import com.qlk.vorder.service.ReserveSessionService;
import com.qlk.vorder.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;

/**
 * ReserveSessionService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-7-28 14:14:00
 * 
 */
@Service
public class ReserveSessionServiceImpl implements ReserveSessionService {

	/** LOG */
	private static final Log LOG = LogFactory.getLog(ReserveSessionServiceImpl.class);

	@Autowired
	private ReserveSessionManager reserveSessionManager;

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.batchInsert")
	public boolean insert(List<ReserveSession> reserveSessionList) {
		boolean resultFlag = false;
		try {
			if (CollectionUtils.isNotEmpty(reserveSessionList)) {
				resultFlag = reserveSessionManager.insert(reserveSessionList);
			} else {
				LOG.warn("ReserveSessionServiceImpl#batchInsert failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#batchInsert has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.insert")
	public boolean insert(ReserveSession reserveSession) {
		boolean resultFlag = false;
		try {
			if (null != reserveSession) {
				resultFlag = reserveSessionManager.insert(reserveSession);
			} else {
				LOG.warn("ReserveSessionServiceImpl#insert failed, param is illegal.");
			}
		} catch (ExistedException e) {
			LOG.warn("ReserveSessionServiceImpl#insert failed, reserveSession has existed.");
			throw e;
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#insert has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.update")
	public boolean update(ReserveSession reserveSession) {
		boolean resultFlag = false;
		try {
			if (null != reserveSession && null != reserveSession.getId()) {
				resultFlag = reserveSessionManager.update(reserveSession);
			} else {
				LOG.warn("ReserveSessionServiceImpl#update failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#update has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.queryReserveSessionList")
	public List<ReserveSession> queryReserveSessionList(ReserveSessionQuery queryBean) {
		List<ReserveSession> reserveSessionList = null;
		try {
			reserveSessionList = reserveSessionManager.queryReserveSessionList(queryBean);
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#queryReserveSessionList has error.", e);
		}
		return reserveSessionList;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.queryReserveSessionListWithPage")
	public List<ReserveSession> queryReserveSessionListWithPage(ReserveSessionQuery queryBean, PageUtil pageUtil) {
		List<ReserveSession> reserveSessionList = null;
		try {
			reserveSessionList = reserveSessionManager.queryReserveSessionListWithPage(queryBean, pageUtil);
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#queryReserveSessionListWithPage has error.", e);
		}
		return reserveSessionList;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.delete")
	public boolean delete(ReserveSession reserveSession) {
		boolean resultFlag = false;
		try {
			if (null != reserveSession && null != reserveSession.getId()) {
				resultFlag = reserveSessionManager.delete(reserveSession);
			} else {
				LOG.warn("ReserveSessionServiceImpl#delete param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#delete has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.batchDelete")
	public boolean delete(ReserveSession[] reserveSessions) {
		boolean resultFlag = false;
		try {
			if (null != reserveSessions && reserveSessions.length > 0) {
				resultFlag = reserveSessionManager.delete(reserveSessions);
			} else {
				LOG.warn("ReserveSessionServiceImpl#batchDelete failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#batchDelete has error.", e);
		}
		return resultFlag;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.getReserveSessionById")
	public ReserveSession getReserveSessionById(Long id) {
		ReserveSession reserveSession = null;
		try {
			if (null != id) {
				reserveSession = reserveSessionManager.getReserveSessionById(id);
			} else {
				LOG.warn("ReserveSessionServiceImpl#getReserveSessionById failed, param is illegal.");
			}
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#getReserveSessionById has error.", e);
		}
		return reserveSession;
	}

	/**
	 * {@inheritDoc}
	 */
	@Profiled(tag = "ReserveSessionService.queryReserveBySessionIdCount")
	public int queryReserveBySessionIdCount(ReserveSessionQuery queryBean) {
		int count = 0;
		try {
			count = reserveSessionManager.queryReserveSessionCount(queryBean);
		} catch (Exception e) {
			LOG.error("ReserveSessionServiceImpl#queryReserveBySessionIdCount has error.", e);
		}
		return count;
	}
}
